local Ip2region = require "Ip2region";

local ip2region = Ip2region.new("/opt/homebrew/Cellar/openresty/1.19.9.1_2/site/lualib/ip2region.db");

local data;

string.split = function(s, p)
  local rt= {}
  string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end )
  return rt
end

data = ip2region:btreeSearch("110.52.252.37");
--data = ip2region:memorySearch("113.245.74.60");
--
-- data = ip2region:btreeSearch("113.245.78.6");
--
-- data = ip2region:memorySearch("113.245.78.6");
--ngx.say(data);
if(data == nil) then
  return nil;
end
local city = '';
local c = string.split(data.region,'|')[4];
if( c == '岳阳') then
  city = 'yy';
elseif (c == '长沙') then
  city = 'cs';
else
  city  = 'xt';
end
return city;

--local str = string.byte('abc',2);
--ngx.say(str);
